#include "BaseDialogWithShadow.h"

#include <QPainter>
#include <QObject>

namespace UserManagementSystem {
BaseDialogWithShadow::BaseDialogWithShadow(QWidget *parent, QPoint pos,QSize size)
    : FramelessWidget{parent}
{
    this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint|Qt::Dialog);
    this->show(); // 重新 show 一下才能生效

    //这个窗口需要设置最大化
    this->showMaximized();
    qDebug()<<__FUNCTION__<<":"<<this->rect();
    // this->setWindowFlags(Qt::FramelessWindowHint);//保证这个属性生效！！非常重要，防止在framelesswidget中设置的属性未生效

    m_contentWidget=new UserManagementSystem::BaseDialog(this,pos,size);


    //绑定关闭窗口的信号槽函数
    QObject::connect(m_contentWidget,&BaseDialog::closeWidget,this,&BaseDialogWithShadow::On_Close_Widgets);


    //绑定关闭窗口信号槽
    connect(m_contentWidget,&BaseDialog::closeWidget,this,[this](){
        this->close();
    });
    m_contentWidget->show();
}

void BaseDialogWithShadow::paintEvent(QPaintEvent *event)
{
    //窗口区域绘制圆角，其他区域绘制阴影
    QPainter painter(this);

    //设置抗锯齿
    painter.setRenderHint(QPainter::Antialiasing);

    //先把整个窗口绘制为半透明灰色
    painter.fillRect(this->rect(),QColor(200,200,200,200));
}

BaseDialog *BaseDialogWithShadow::GetContentWidget() const
{
    return m_contentWidget;
}

void BaseDialogWithShadow::On_Close_Widgets()
{
    this->close();
}
};

